package com.haixin.security.web;

import com.haixin.security.bean.Role;
import com.haixin.security.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @GetMapping
    public List<Role> getAllRoles() {
        return roleService.getAllRoles();
    }

    @GetMapping("/{id}")
    public Role getRoleById(@PathVariable int id) {
        return roleService.getRoleById(id);
    }

    @PostMapping
    public boolean addRole(@RequestBody Role role) {
        return roleService.addRole(role);
    }

    @PutMapping
    public boolean updateRole(@RequestBody Role role) {
        return roleService.updateRole(role);
    }

    @DeleteMapping("/{id}")
    public boolean deleteRole(@PathVariable int id) {
        return roleService.deleteRole(id);
    }
}
